package com.kevinkk.array;

import java.util.Scanner;

/**
 * 给定一个整数数组 Array，请计算该数组在每个指定区间内元素的总和。
 *
 * 采用前缀和的方式来计算区间的和
 */

public class IntervalSum {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n], preSum = new int[n];

        for(int i = 0; i < n; i++){
            int num = sc.nextInt();
            if(i == 0){
                preSum[i] = num;
            }else{
                preSum[i] = preSum[i-1] + num;
            }
            arr[i] = num;
        }

        while(sc.hasNextInt()){
            int left = sc.nextInt(), right = sc.nextInt();
            System.out.println(preSum[right] - preSum[left] + arr[left]);
        }
    }
}
